import axios from 'axios'
import { Message } from 'element-ui'

// 创建axios实例
const medicalService = axios.create({
  baseURL: 'http://10.30.20.27:8080/mbs-fsi/web/api/fsi',
  timeout: 30000,
  headers: {
    'Content-Type': 'application/json'
  }
})

// 请求拦截器
medicalService.interceptors.request.use(config => {
  // 可在此处添加统一请求处理
  return config
})

// 响应拦截器
medicalService.interceptors.response.use(
  response => {
    if (response.data.infcode == -1) {
      Message({
        message: response.data.err_msg,
        type: 'error',
        duration: 5 * 1000
      })
      return Promise.reject(response.data)
    }
    return response.data
  },
  error => {
    return Promise.reject(error)
  }
)

// 封装调用医保专用POST方法
export const ybPost = (data) => {
  return medicalService.request({
    method: 'post',
    url: '/callService',
    data
  })
}
